package Demo_01;

import java.sql.*;

public class SelectDemo {
    public static void main(String[] args) {
        String driver = "com.mysql.jdbc.Driver";
        //数据库名在localhost上存在才可以

        String url = "jdbc:mysql://localhost:3306/jdbc?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false";
        String user = "root";
        String password = "root123";

        Connection conn = null;
        Statement stmt = null;
        ResultSet rst = null;

        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try {
            conn = DriverManager.getConnection(url,user,password);
            String sql = "select * from tbl_book_info";
            stmt = conn.createStatement();
            rst = stmt.executeQuery(sql);
            while (rst.next()){
                //判断是否有下一行数据，如果有返回true，没有返回false
                //如果赌债自行要求不高，可以统一使用String
                //
                int id = rst.getInt("b_no");
                String name = rst.getString("b_name");
                System.out.println(id+"\t"+name);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
